package com.sport.ui.home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sport.R;
import com.sport.pojo.ProductBean;

import java.util.List;

public class BottomAdapter extends BaseAdapter {
    private Context mContext;
    private List<ProductBean> list;
    public BottomAdapter(Context context , List<ProductBean> list) {
        this.mContext = context;
        this.list=list;
    }
    @Override
    public int getCount() {       //获取列表条目的总数
        return list.size();       //返回ListView 条目的总数
    }
    @Override
    public Object getItem(int position) {
        return list.get(position); //返回列表条目的数据对象
    }
    @Override
    public long getItemId(int position) {
        return position; //返回列表条目的id
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.recycler_item, null);
            holder = new ViewHolder();
            //填写代码，初始化holder成员变量
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            holder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            //
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        // 获得条目内容对象
        ProductBean bean=list.get(position);
        // 是list_item里的
        holder.tv_title.setText(bean.getName());
        holder.iv_img.setBackgroundResource(bean.getImg());
        return convertView;
    }
    class ViewHolder {
        TextView tv_title;
        ImageView iv_img;
    }
}

